package ray.shader;

import ray.Light;
import ray.math.Color;
import ray.math.Point3;
import ray.math.Ray;
import ray.math.Vector3;

/**
 * A Lambertian material scatters light equally in all directions. BRDF value is
 * a constant
 *
 * @author ags
 */
public class Lambertian implements Shader {
	
	/** The color of the surface. */
	protected final Color diffuseColor = new Color(1, 1, 1);
	public void setDiffuseColor(Color inDiffuseColor) { diffuseColor.set(inDiffuseColor); }
	
	public Lambertian() { }
	
	/**
	 * @see Object#toString()
	 */
	public String toString() {
		return "lambertian: " + diffuseColor;
	}
	
	// Note this function is not called
	public Color getColor(){
		return diffuseColor;
	}
	
	public Color shade(Ray ray,Point3 point,Vector3 normal,Light light){
		Vector3 l = new Vector3();
		
		l.sub(light.position,point);
		l.normalize();
		
		double m = normal.dot(l);
		
		Color lightDiffuse = new Color();
		
		lightDiffuse.scaleAdd(Math.max(0.0,m), light.intensity); // FIX check if need max
				
		Color shade = new Color();
		shade.set(diffuseColor);
		shade.scale(lightDiffuse);
		
		return shade;
	}
	
}
